﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Data;

public partial class Administrator_ajax_AjaxPage : System.Web.UI.Page
{
    [WebMethod]
    public static string Ajax_GetInfoUser(int UserID)
    {
        string sJS = "";
        try
        {
            DataTable dt = new DataTable();
            Admin.DB.GetDataTable(ref dt, "spUser_GetInfoUserByUserID", UserID);
            sJS += "var FullName='" + dt.Rows[0][1].ToString() + "';";
            sJS += "var NickName='" + dt.Rows[0][2].ToString() + "';";
            sJS += "var Email='" + dt.Rows[0][4].ToString() + "';";
            sJS += "var Birthday='" + dt.Rows[0][5].ToString() + "';";
            sJS += "var Url='" + dt.Rows[0][6].ToString() + "';";
        }
        catch (Exception ex)
        {
            Process_Catch(ex);
        }
        return sJS;
    }

    [WebMethod]
    public static string Ajax_GetMoreUser(int PageNum, int PageSize)
    {
        string sJS = "";
        try
        {
            DataTable dt = new DataTable();
            Admin.DB.GetDataTable(ref dt, "spUser_GetMoreUser", PageNum, PageSize);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                sJS += String.Format("<tr id='tr{0}'>",dt.Rows[i]["UserID"]);
                sJS += "<td class=\"center\">" + dt.Rows[i]["UserID"] + "</td>";
                sJS += "<td>" + dt.Rows[i]["FullName"] + "</td>";
                sJS += "<td>" + dt.Rows[i]["NickName"] + "</td>";
                sJS += "<td>" + dt.Rows[i]["Sex"] + "</td>";
                sJS += "<td>" + dt.Rows[i]["Email"] + "</td>";
                sJS += "<td>" + dt.Rows[i]["Birthday"] + "</td>";
                sJS += "<td>" + dt.Rows[i]["Url"] + "</td>";
                sJS += "<td> <div class=\"btn-group\"><a class=\"btn dropdown-toggle\" data-toggle=\"dropdown\" href=\"javascript:void(0);\">Action<span class=\"caret\"></span></a>";
                sJS += "<ul class=\"dropdown-menu\">";
                sJS += String.Format("<li><a onclick='Ajax_EditUser({0});' href=\"javascript:void(0);\">Edit</a></li>", dt.Rows[i]["UserID"].ToString());
                sJS += String.Format("<li><a onclick='Ajax_DeleteUser({0});' href=\"javascript:void(0);\">Delete</a></li>", dt.Rows[i]["UserID"].ToString());
                sJS += "</ul></div></td></tr>";
            }
        }
        catch (Exception ex)
        {
            Process_Catch(ex);
        }
        return sJS;
    }

    [WebMethod]
    public static string Ajax_DeleteUser(int UserID)
    {
        string sJS = "";
        try
        {
            Admin.DB.ExecCommand("spUser_Delete", UserID);
            sJS += "var ErrCode='0';";
        }
        catch (Exception ex)
        {
            Process_Catch(ex);
        }
        return sJS;
    }

    static string Process_Catch(Exception ex)
    {
        string sJS = "";
        sJS += "var ErrCode=1;";
        string exc = ex.ToString();
        exc = exc.Replace("'", "&#34;");
        exc = exc.Replace("\r\n", "<br/>");
        sJS += "var ErrMsg=\"" + exc + "\";";
        return sJS;

    }
}



